

//
//  DisCollectionReusableView.m
//  xiaowanTravel
//
//  Created by wyzcWLB on 16/10/7.
//  Copyright © 2016年 wyzcWLB. All rights reserved.
//

#import "DisCollectionReusableView.h"
#import <UIImageView+WebCache.h>

@implementation DisCollectionReusableView

- (void)awakeFromNib {
    
}
-(instancetype)initWithFrame:(CGRect)frame{
    self=[super initWithFrame:frame];
    if (self) {
        self.frame=CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 250);
        [self creatadView];
    }
    return self;
}
-(void)creatadView
{
    //创建广告栏
    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 250)];
    _scrollView.delegate = self;
    _scrollView.pagingEnabled = YES;
    _scrollView.userInteractionEnabled = YES;
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
    [self addSubview:_scrollView];
    
    
    self.imageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 252, 10, 25)];
    self.imageV.image = [UIImage imageNamed:@"bg_profile_passport_blue"];
    
    
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 252, [UIScreen mainScreen].bounds.size.width-15, 25)];
    self.titleLabel.font=[UIFont systemFontOfSize:18];
    self.titleLabel.textColor=[UIColor blackColor];
    self.titleLabel.text = @"热门城市";
    self.titleLabel.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.titleLabel];
    [self addSubview:self.imageV];
    
    
    
    //创建计时器
    _timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(time) userInfo:nil repeats:YES];
}

//开始拖拽会调用该方法
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    //关闭定时器  定时器对象就会销毁
    [_timer invalidate];
    _timer = nil;
}

//当结束拖拽后 在重新建立定时器
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    
    _timer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(time) userInfo:nil repeats:YES];
    
}

-(void)time{
    //要想实现偏移 就要告诉scrollView的contentOffset的偏移
    _scrollView.contentOffset=CGPointMake(_scrollView.contentOffset.x+self.frame.size.width, 0);
    NSInteger index=_scrollView.contentOffset.x/self.frame.size.width;
    
    if (index==_array.count) {
        index=0;
        _scrollView.contentOffset=CGPointZero;
    }
    
}



@end
